package com.bw.common.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.bw.common.R;
import com.bw.common.databinding.WidgetNormaltitlebarBinding;

/**
 * @author:created by hahajing
 * 时间：2024/4/29 0029
 * 企鹅号:444511958
 * 描述:
 */
public class NormalTitleBar extends LinearLayout {
    private String title;
    private BackOnClickListener onClickListener;
    private  WidgetNormaltitlebarBinding binding;

    public void setTitle(String title) {
        this.title = title;
        binding.tvWidgetNormaltitlebarTitle.setText(title);
    }

    public void setOnClickListener(BackOnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public NormalTitleBar(Context context) {
        super(context);
        initView();
    }



    public NormalTitleBar(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public NormalTitleBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView() {
        View view = LayoutInflater.from(this.getContext()).inflate(R.layout.widget_normaltitlebar,this,false);
        binding= WidgetNormaltitlebarBinding.bind(view);
        binding.tvWidgetNormaltitlebarTitle.setText(title);
        binding.ivWidgetNormaltitlebarBack.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                if (onClickListener!=null){
                    onClickListener.onClick();
                }
            }
        });
        this.addView(view);
    }

    public interface BackOnClickListener{
        void onClick();
    }


}
